﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Autofac;
using ComputerVision.Common;
using ComputerVision.Data;
using ComputerVision.Services;
using RawInput_dll;

namespace ComputerVision.VeXeForm
{
    public partial class frmCheck : Form
    {
        private DataGridView dgv;

        public frmCheck(frmKiemTaThe frm)
        {
            InitializeComponent();
            dgv = frm.dgvSoVe;
        }

        private void frmCheck_Load(object sender, EventArgs e)
        {

        }

        private void Check()
        {
            string idx = txtSoVe.Text.Trim();
            if (idx.Length > 0 && dgv.Rows.Count > 0)
            {
                Cursor.Current = Cursors.WaitCursor;

                int j = dgv.Rows.Count - 1;
                int iRowIndex = -1;
                for (int i = 0; i < Convert.ToInt32(dgv.Rows.Count / 2) + 1; i++)
                {
                    if (dgv.Rows[i].Cells[0].Value.ToString() == idx)
                    {
                        iRowIndex = i;
                        break;
                    }
                    if (dgv.Rows[j].Cells[0].Value.ToString() == idx)
                    {
                        iRowIndex = j;
                        break;
                    }
                    j--;
                }
                if (iRowIndex != -1)
                    dgv.Rows.RemoveAt(iRowIndex);
                Cursor.Current = Cursors.Default;

            }
        }

        private void btKiemTra_Click(object sender, EventArgs e)
        {
            txtSoVe.ReadOnly = true;
            btKiemTra.Enabled = false;
            Check();
            txtSoVe.ReadOnly = false;
            btKiemTra.Enabled = true;
            txtSoVe.SelectAll();
        }
    }
}
